package Welsy4.Connect.business
{
	import flash.net.URLVariables;
	import Welsy4.Connect.vo.LoginVO;	
	import Welsy4.Connect.vo.User;
	import Welsy4.Connect.model.ConnectModel;	
	import com.adobe.cairngorm.business.ServiceLocator;	
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.http.HTTPService;
	
	public class LoginDelegate
	{		
		private var responder : IResponder;
        private var service : Object;
                
        public function LoginDelegate( responder : IResponder )
        {
            this.service = ServiceLocator.getInstance().getHTTPService("FakeAPI" );
            this.responder = responder;
        }
        /*
		 * 
		 *  INFO su LOGIN esterna
		 *  a) action=login&external-auth=use
		 * 
		 * 
		 * 
		 * */
        public function Execute( _login : LoginVO ): void
        {
            //qui aggiungi i parametri alla http request e la esegui  
			var loginRequest:URLVariables = new URLVariables();
			
			loginRequest.action = "login";
			loginRequest.login = _login.login;
			loginRequest.password = _login .password;
			loginRequest.nocache = _login.getLoginRequestlocaleTime;
            
			Alert.show("Login inviata");
			var token : AsyncToken = HTTPService(service).send(loginRequest);
			                        
            token.addResponder(responder);
            
        }
		
		public function Logout():void {
		    var token : AsyncToken = HTTPService(service).send(new URLVariables("action=logout&nocache="+User.getLoginRequestlocaleTime()));
			token.addResponder(responder);	
		}
       
    }
}